package com.cgtong.android.mvp.model;

import com.cgtong.android.bean.UserInfoBean;
import com.cgtong.android.http.ApiManager;
import com.cgtong.android.mvp.contract.GetUserContract;
import com.zhouyou.http.EasyHttp;
import com.zhouyou.http.callback.SimpleCallBack;
import com.zhouyou.http.exception.ApiException;


public class GetUserModel implements GetUserContract.Model {

    @Override
    public void getUserInfo(final SimpleCallBack<UserInfoBean.UserInfoBeanObj> callBack) {
        EasyHttp.post(ApiManager.URL_GETUSERBYTOKEN)
                .execute(new SimpleCallBack<UserInfoBean.UserInfoBeanObj>() {
                    @Override
                    public void onError(ApiException e) {
                        callBack.onError(e);
                    }

                    @Override
                    public void onSuccess(UserInfoBean.UserInfoBeanObj userInfoBeanObj) {
                        callBack.onSuccess(userInfoBeanObj);
                    }
                });
    }

    @Override
    public void setUserInfo(String name, String nickname, String idcard,
                            String avasterid, String phone, String sex,String location, final SimpleCallBack<String> callBack) {
        EasyHttp.post(ApiManager.URL_UPDATEUSER)
                .params("name", name)
                .params("nickname", nickname)
                .params("idcard", idcard)
                .params("avasterid", avasterid)
                .params("phone", phone)
                .params("sex", sex)
                .params("address",location)
                .execute(new SimpleCallBack<String>() {
                    @Override
                    public void onError(ApiException e) {
                        callBack.onError(e);
                    }

                    @Override
                    public void onSuccess(String result) {
                        callBack.onSuccess(result);
                    }
                });
    }
}